<?php
/*
  $menu = Blyn::app()->getAppUI()->getMenu('leftMenu');
  $workingMenus = Blyn::app()->getAppUI()->menus[BUIApp::Menu_WorkingSpacesLinks];
  $followingMenus = Blyn::app()->getAppUI()->menus[BUIApp::Menu_FollowingSpacesLinks];
 * 
 */

$appLinks = Blyn::app()->getAppUI()->getLinks();
$workingMenus = $appLinks['workingSpaceLinks'];
$followingMenus = $appLinks['followingSpaceLinks'];

$currentScreen = Blyn::app()->getCurrentNode()->getUIManager()->getCurrentScreen();

/* define link of "working" and "following" for Space box */
$workingTabLink = $currentScreen->getUrl(array('ajaxLink' => array('id' => 'workingLink', 'name' => 'Working')));
$followingTabLink = $currentScreen->getUrl(array('ajaxLink' => array('id' => 'followingLink', 'name' => 'Following')));
$visitTabLink = $currentScreen->getUrl(array('ajaxLink' => array('id' => 'visitLink', 'name' => 'Most Visits')));

$spaceTabLinks = array();
//by default, set most visits tab as active
$spaceTabLinks['visits'] = array('ajaxUrl' => $visitTabLink, 'active' => 'active');
$spaceTabLinks['working'] = array('ajaxUrl' => $workingTabLink, 'active' => '');
$spaceTabLinks['following'] = array('ajaxUrl' => $followingTabLink, 'active' => '');


if ($currentScreen->isAjaxLinkClicked('visitsLink')) {
    $spaceTabLinks['visits']['active'] = '';
}

if ($currentScreen->isAjaxLinkClicked('workingLink')) {
    $spaceTabLinks['working']['active'] = 'active';
    $spaceTabLinks['visits']['active'] = '';
}

if ($currentScreen->isAjaxLinkClicked('followingLink')) {
    $spaceTabLinks['following']['active'] = 'active';
    $spaceTabLinks['visits']['active'] = '';
}


?>
<div class="container" style="margin: auto;min-height: 500px;padding-top: 20px">
    
    <div class="row-fluid">
        <div class="span8" style="padding-right: 40px">
            <?php
            $views = $uiObj->getViews();

            foreach ($views as $view) {
                $uiObj->renderView($view['view'], $view['data']);
            }
            ?>
        </div>
        <div class="span4">
            <div><h4>Spaces:</h4></div>
            <div class="workflow-box" style="padding: 0px">                
                <div style="padding: 8px 8px 8px 6px;background-color: #F5F5F5;height: 29px;border: 1px solid #ccc;">                
                    <ul class="nav nav-tabs">
                        <?php foreach ($spaceTabLinks as $link) { ?>
                            <li class="<?php echo $link['active']; ?>">
                                <?php echo $link['ajaxUrl']; ?>
                            </li>
                        <?php } ?>                        
                    </ul>
                </div>
                <div style="min-height: 200px;padding-top: 20px;padding-left: 5px">
                    <ul class="nav nav-list">
                        <?php
                        if ($spaceTabLinks['working']['active'] == 'active') {
                            foreach ($workingMenus as $link) {
                                ?>
                                <li>
                                    <?php echo $link['ajaxUrl']; ?>
                                </li>
                                <?php
                            }
                        }
                        ?>
                        <?php
                        if ($spaceTabLinks['following']['active'] == 'active') {
                            foreach ($followingMenus as $link) {
                                ?>
                                <li>
                                    <?php echo $link['ajaxUrl']; ?>
                                </li>
                                <?php
                            }
                        }
                        ?>
                        <?php if ($spaceTabLinks['visits']['active'] == 'active') { ?>
                            <li class="nav-header">working Spaces</li>
                            <?php
                            foreach ($workingMenus as $link) {
                                ?>
                                <li>
                                    <?php echo $link['ajaxUrl']; ?>
                                </li>
                                <?php
                            }
                            ?>
                            <li class="nav-header">following Spaces</li>     
                            <?php foreach ($followingMenus as $link) {
                                ?>
                                <li>
                                    <?php echo $link['ajaxUrl']; ?>
                                </li>
                                <?php
                            }
                        }
                        ?>
                    </ul>

                </div>
            </div>
        </div>
    </div>
</div>

